package chapter04;

import java.io.File;

public class IterateAllFile {

    public static void main(String[] args) {
        String path = "C:\\Users\\BBB\\Documents\\李锦记\\prod";
        File file = new File(path);
        fun(file);

        long size = size(file);
        System.out.println(size);
    }

    /**
     * 打印目录的文件
     * @param file
     */
    private static void fun(File file) {
        File[] files = file.listFiles();
        for (File f: files) {
            if (f.isDirectory()) {
                fun(f);
            }else {
                //if (f.getName().endsWith(".png"))
                System.out.println(f.length() + "\t\t" + f );
            }
        }
    }

    public static long size(File file) {
        long totolSize = 0;
        File[] files = file.listFiles();
        for (File f: files) {
            if(f.isDirectory()) {
                totolSize += size(f);
            }else {
                totolSize += f.length();
            }
        }
        return totolSize;
    }
}
